home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / BBS / TAG2MAX.ZIP / FILECNV.CPP next >
Encoding:
C/C++ Source or Header  |  1996-02-11  |  4.8 KB  |  213 lines

  1. // filecnv.cpp
  2. // File Area Conversion Tag 2.7 to Maximus 3.01
  3. // (C) Copyright 1996, TranStar Technologies
  4. // 02/10/96 - Version 1.0
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #pragma pack(1)
  10. #include "\bbsdev\tag.h"
  11. //#include "max.h"
  12. #pragma pack()
  13. #include <share.h>
  14. #include <conio.h>
  15.  
  16. #define TRUE    1
  17. #define FALSE   0
  18.  
  19. typedef unsigned char BYTE;
  20. typedef unsigned short WORD;
  21.  
  22. FILE *instream, *outstream;
  23. UlRec fboard;
  24. short count = 0;
  25. char ListFile[64];
  26. UlfRec farea;
  27.  
  28. void strip(char *string);
  29. void __pascal pas2c(char *source, char *dest);
  30. void TStrip(char *string);
  31. BYTE ask(char *string);
  32. void ConvertBoard();
  33. void WriteListFile();
  34. void fixname(char *filename);
  35.  
  36. void main(int argc, char **argv)
  37. {
  38.     printf("FILECNV 1.0 - Tag 2.7x to Maximus 3.01 File Area Converter\n");
  39.     printf("(C) Copyright 1996, TranStar Technologies\n\n");
  40.     if (argc!=3) {
  41.         printf("Usage: path-fboards.dat path-fareas.ctl\n");
  42.         exit(0);
  43.     }
  44.     if ((instream = _fsopen(argv[1], "rb", _SH_DENYNO)) == NULL) {
  45.         printf("Can't open %s\n", argv[1]);
  46.         exit(0);
  47.     }
  48.     if ((outstream = fopen(argv[2], "wt")) == NULL) {
  49.         printf("Can't create %s\n", argv[2]);
  50.         fclose(instream);
  51.         exit(0);
  52.     }
  53.  
  54.     while(!feof(instream)) {
  55.         if (fread(&fboard, sizeof(UlRec), 1, instream) != 1) break;
  56.         ConvertBoard();
  57.         count++;
  58.     }
  59.     fclose(instream);
  60.     fclose(outstream);
  61.     printf("\n%d file areas defined.\n", count);
  62. }
  63.  
  64.  
  65. void strip(char *string)
  66. {
  67.     short c;
  68.  
  69.     if (string[strlen(string) - 1] == '\n')
  70.         string[strlen(string) - 1] = 0;
  71.     if (string[strlen(string) - 1] == '\r')
  72.         string[strlen(string) - 1] = 0;
  73.     while(1) {
  74.         c = (short)strlen(string);
  75.         if (!c) break;
  76.         if (string[c - 1] != ' ') break;
  77.         string[c - 1] = 0;
  78.     }
  79. }
  80.  
  81. void __pascal pas2c(char *source, char *dest)
  82. {
  83.     short slen;
  84.     char *p;
  85.  
  86.     p = source;
  87.     slen = *p;
  88.     p++;
  89.     memcpy(dest, p, slen);
  90.     dest[slen] = 0;
  91. }
  92.  
  93.  
  94. void TStrip(char *string)
  95. {
  96.     char tmp[80], *p, *q;
  97.  
  98.     p = string;
  99.     q = tmp;
  100.     while(*p) {
  101.         if (*p == 3) {
  102.             p += 2;
  103.             continue;
  104.         }
  105.         *q = *p;
  106.         p++;
  107.         q++;
  108.     }
  109.     *q = 0;
  110.     strcpy(string, tmp);
  111. }
  112.  
  113.  
  114. BYTE ask(char *string)
  115. {
  116.     short c;
  117.     
  118. reget:
  119.     printf("%s (Y/N)? ", string);
  120.     c = getche();
  121.     c = toupper(c);
  122.     printf("%c\n", c);
  123.     if (c == 'Y') return TRUE;
  124.     if (c == 'N') return FALSE;
  125.     goto reget;
  126. }
  127.  
  128. void ConvertBoard()
  129. {
  130.     char tmp[132];
  131.  
  132.     pas2c((char *)fboard.Name, tmp);
  133.     TStrip(tmp);
  134.     printf("%3d: %s\n", count, tmp);
  135.  
  136.     fprintf(outstream, "FileArea %d\n", count);
  137.     fprintf(outstream, "\tDesc\t\t%s\n", tmp);
  138.     fprintf(outstream, "\tACS\t\t%d", (short)fboard.DSL);
  139.     if (fboard.ArLvl != '@') fprintf(outstream, "/%c", (char)fboard.ArLvl);
  140.     fprintf(outstream, "\n");
  141.     pas2c((char *)fboard.DlPathname, tmp);
  142.     fprintf(outstream, "\tDownload\t\t%s\n", tmp);
  143.     strcpy(ListFile, tmp);
  144.     pas2c((char *)fboard.UlPathName, tmp);
  145.     fprintf(outstream, "\tUpload\t\t%s\n", tmp);
  146.  
  147.     pas2c((char *)fboard.Filename, tmp);
  148.     if (tmp[0] == '`' || tmp[0] == '@') {
  149.         fprintf(outstream, "\tFileList\t\t");
  150.         sprintf(ListFile, "File\\%s.BBS", &tmp[1]);
  151.         fprintf(outstream, "File\\%s.BBS\n", &tmp[1]);
  152.     } else {
  153.         strcat(ListFile, tmp);
  154.         strcat(ListFile, ".BBS");
  155.     }
  156.     if (fboard.Flags.IsCdRom)
  157.         fprintf(outstream, "\tType\t\tCD\n");
  158.     fprintf(outstream, "End FileArea\n\n");
  159.     if (ask("Convert area")) WriteListFile();
  160. }
  161.  
  162.  
  163. void WriteListFile()
  164. {
  165.     FILE *dirstream, *bbsstream;
  166.     char *p, tmp[132];
  167.     
  168.     strcpy(tmp, ListFile);
  169.     p = strstr(tmp, ".BBS");
  170.     if (p == NULL) return;
  171.     strcpy(p, ".DIR");
  172.     if ((dirstream = _fsopen(tmp, "rb", _SH_DENYNO)) == NULL) {
  173.         printf("Cannot open TAG DIR file %s\n", tmp);
  174.         return;
  175.     }
  176.     if ((bbsstream = fopen(ListFile, "wt")) == NULL) {
  177.         printf("Cannot make BBS file %s\n", ListFile);
  178.         fclose(dirstream);
  179.         return;
  180.     }
  181.     
  182.     while(!feof(dirstream)) {
  183.         if (fread(&farea, sizeof(UlfRec), 1, dirstream) != 1) break;
  184.         pas2c((char *)farea.Filename, tmp);
  185.         fixname(tmp);
  186.         fprintf(bbsstream, "%-12s ", tmp);
  187.         pas2c((char *)farea.Description, tmp);
  188.         fprintf(bbsstream, "%s\n", tmp);
  189.     }
  190.     fclose(dirstream);
  191.     fclose(bbsstream);
  192. }
  193.  
  194.         
  195. void fixname(char *filename)
  196. {
  197.     char *p, *q, tmp[20];
  198.     
  199.     p = filename;
  200.     q = tmp;
  201.     while(*p) {
  202.         if (*p == ' ') {
  203.             p++;
  204.             continue;
  205.         }
  206.         *q = *p;
  207.         q++;
  208.         p++;
  209.     }
  210.     *q = 0;
  211.     strcpy(filename, tmp);
  212. }
  213.